public class RomanTranslate {
    public static void main(String[] args) {
        RomanTranslate romanTranslate=new RomanTranslate();
        System.out.println(romanTranslate.romanToInt("IXIV"));
    }

        public int romanToInt(String s) {
            int num=0;
            for(int i=0;i<s.length();i++){
                char ch1=s.charAt(i);
                char ch2=' ';
                if(i+1<s.length()){
                    ch2=s.charAt(i+1);
                }
                if(ch1=='I'&&ch2=='V'){
                    num+=4;
                    i++;
                }
                else if(ch1=='I'&&ch2=='X'){
                    num+=9;
                    i++;
                }
                else if(ch1=='X'&&ch2=='L'){
                    num+=40;
                    i++;
                }
                else if(ch1=='X'&&ch2=='C'){
                    num+=90;
                    i++;
                }
                else if(ch1=='C'&&ch2=='D'){
                    num+=400;
                    i++;
                }
                else if(ch1=='C'&&ch2=='M'){
                    num+=900;
                    i++;
                }
                else if(ch1=='I')num+=1;
                else if(ch1=='V')num+=5;
                else if(ch1=='X')num+=10;
                else if(ch1=='L')num+=50;
                else if(ch1=='C')num+=100;
                else if(ch1=='D')num+=500;
                else if(ch1=='M')num+=1000;
            }
            return num;
        }
}
